﻿module Runner {
    export enum EnemyAIType {
        Wander,
        Seek,
        Patrol,
        Sentry
    }

    export function aiWander(sprite: Runner.Enemy) {
        var restitution = 1.5;
        if (Physics.touchingVertical(sprite,'bottom')) {
            sprite.body.velocity.x = 0;

            if (Physics.touchingSide(sprite, 'left')) {
                sprite.enemyHit();
                sprite.body.x += restitution;
            } else if (Physics.touchingSide(sprite, 'right')) {
                sprite.enemyHit();
                sprite.body.x -= restitution;
            }

            if (sprite.facing == 0) {
                sprite.body.velocity.x -= sprite.speed;
            } else {
                sprite.body.velocity.x += sprite.speed;
            }
        }
    }

    export function aiSeek(sprite: Runner.Enemy, hero: Runner.Hero) {
        if (!Physics.touchingSide(sprite)) {
            if (Physics.touchingVertical(sprite, 'bottom')) {
                Physics.moveTo(sprite, hero, sprite.speed);
            }
        }
    }
}